package com.android.openapp.services;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DBHelper extends SQLiteOpenHelper{

	public static final String TABLE_NAME = "saved_place";
	public static final String COLUMN_ID = "_id"; //è necessario usare questo nome per la colonna id, altrimenti
												//i corsor adapter non funzioneranno
	public static final String PLACE_CL="place";
	public static final String index_PL="index_pl";
	private static final String DATABASE_NAME = "places.db";
	private static final int DATABASE_VERSION = 1;
	
	private static final String DATABASE_CREATE_QUERY = "create table if not EXISTS "
		      + TABLE_NAME + " (" + COLUMN_ID
		      + " integer primary key autoincrement," +
		      index_PL+" int not null," +
		      PLACE_CL+" blob not null);";
	
	//sigleton: solo un'istanza dell'helper
	private static DBHelper helper;
	
	public static DBHelper getHelper(Context c){
		if(helper == null)
			helper = new DBHelper(c);
		
		return helper;
	}
	
	private DBHelper(Context c){
		super(c,DATABASE_NAME,null,DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE_QUERY);
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
	}

}